package dataint;

import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

/**
 *
 * @author philippdirding
 */
public class Customer {

    private String firstName;

    /**
     * Get the value of firstName
     *
     * @return the value of firstName
     */
    public String getFirstName() {
        return this.escapeTab(firstName);
    }

    /**
     * Set the value of firstName
     *
     * @param firstName new value of firstName
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    private String lastName;

    /**
     * Get the value of lastName
     *
     * @return the value of lastName
     */
    public String getLastName() {
        return this.escapeTab(lastName);
    }

    /**
     * Set the value of lastName
     *
     * @param lastName new value of lastName
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    private String streetAddress;

    /**
     * Get the value of streetAddress
     *
     * @return the value of streetAddress
     */
    public String getStreetAddress() {
        return this.escapeTab(streetAddress);
    }

    /**
     * Set the value of streetAddress
     *
     * @param streetAddress new value of streetAddress
     */
    public void setStreetAddress(String streetAddress) {
        this.streetAddress = streetAddress;
    }

    private String city;

    /**
     * Get the value of city
     *
     * @return the value of city
     */
    public String getCity() {
        return this.escapeTab(city);
    }

    /**
     * Set the value of city
     *
     * @param city new value of city
     */
    public void setCity(String city) {
        this.city = city;
    }

    private String phoneNo;

    /**
     * Get the value of phoneNo
     *
     * @return the value of phoneNo
     */
    public String getPhoneNo() {
        return this.escapeTab(phoneNo);
    }

    /**
     * Set the value of phoneNo
     *
     * @param phoneNo new value of phoneNo
     */
    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }

    private String email;

    /**
     * Get the value of email
     *
     * @return the value of email
     */
    public String getEmail() {
        return this.escapeTab(email);
    }

    /**
     * Set the value of email
     *
     * @param email new value of email
     */
    public void setEmail(String email) {
        // the string will be converted to lowercase characters as demanded by
        // the exercise
        this.email = email.toLowerCase(Locale.GERMAN);
    }

    private String premium;

    /**
     * Get the value of premium
     *
     * @return the value of premium
     */
    public String getPremium() {
        return this.escapeTab(premium);
    }

    /**
     * Set the value of premium
     *
     * @param premium new value of premium
     */
    public void setPremium(String premium) {
        this.premium = premium;
    }

    private String date;

    /**
     * Get the value of date
     *
     * @return the value of date
     */
    public String getDate() {
        return this.escapeTab(date);
    }

    /**
     * Set the value of date
     *
     * @param date new value of date
     */
    public void setDate(String date) {
        this.date = date;
    }

    private Double TOV;

    /**
     * Get the value of TOV
     *
     * @return the value of TOV
     */
    public Double getTOV() {
        return TOV;
    }

    /**
     * Formats the TOV (total order value) float value to a string with exactly
     * 2 decimal digits
     *
     * @return the value of TOV with two decimal digits
     */
    private String getTOVString()
    {
        DecimalFormat dec = new DecimalFormat();
        dec.setMaximumFractionDigits(2);
        dec.setMinimumFractionDigits(2);

	dec.setRoundingMode(RoundingMode.HALF_UP);

	dec.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.ENGLISH));

        dec.setGroupingUsed(false); // turns of the group delimitation

        return dec.format(TOV);
    }

    /**
     * Set the value of TOV
     *
     * @param TOV new value of TOV
     */
    public void setTOV(Double TOV) {
        this.TOV = TOV;
    }

    /**
     * Checks the string for tab stops and escapes the whole string it contains some
     * 
     * @param str
     * @return
     */
    private String escapeTab(String str) {
	if (str.contains("\t")) {
	    return "\"" + str + "\"";
	} else {
	    return str;
	}
    }


    public Customer() {
    }

    /**
     * Builds the final string for the console output
     *
     * @return String with all the values demanded by exercise
     */
    @Override
    public String toString(){
        String str = this.getFirstName() + "\t";
        str = str + this.getLastName() + "\t";
        str = str + this.getStreetAddress() + "\t";
        str = str + this.getCity() + "\t";
        str = str + this.getPhoneNo() + "\t";
        str = str + this.getEmail() + "\t";
        str = str + this.getPremium() + "\t";
        str = str + this.getDate() + "\t";
        str = str + this.getTOVString();
        return str;

    }

    public Boolean equals(Customer c){
        if ((this.firstName.equals(c.getFirstName()) && this.lastName.equals(c.getLastName())))
            return true;
        else
            return false;
    }
}
